<?php
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{  $item['id'] = addItem($_POST['name'], $_POST['type']); }
			break;
	}
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
		
	if($item['id'] > 0)
	{  
		$item = getItem($item['id']);  
		if(($_GET['active'] != "") && ($_GET['active'] != $item['active']))
		{
			$result = mysql_query("UPDATE ".DB_PERFIX."template_images SET active = '".$_GET['active']."' WHERE id = '".$item['id']."'");
		}
		if(($_GET['type'] != "") && ($item['id'] > 0))
		{ setItemType($item['id'], $_GET['type']); }
		
		if(($_POST['name'] != $item['name']) && ($_POST['name'] != ""))
		{ setItemName($item['id'], $_POST['name']); }
		
		if($_POST['url'] != "")
		{ setItemStyle($item['id'], $_POST['style']); }
		
		if($_POST['style'] != $item['style'])
		{ setItemStyle($item['id'], $_POST['style']); }
		
		if($_POST['delete_item'] > 0)
		{ deleteItem($_POST['delete_item']); }
		
		if ($_FILES['image']['name'] != "")
		{
			$error = uploadItemImage($item['id'], $item['image']);
		}
		
	}
	
	if($item['id'] > 0)
	{ $item = getItem($item['id']); }
?>